package com.eascs.accessory.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.eascs.accessory.entity.Accessory;
import com.eascs.admin.common.dao.BaseO2oDao;

@Repository
public class AccessoryDao extends BaseO2oDao{
	
	public List<Accessory> selectAccessoryList(){
		StringBuffer sql=new StringBuffer();
    	sql.append(" SELECT res.id,res.resource_name,res.resource_code,res.resource_type,res.resource_url,res.parent_id,res.sort,res.create_time,res.update_time");
    	sql.append(" FROM o2o_guideline AS res");
    	sql.append(" ORDER BY res.parent_id ASC,res.sort ASC");
        List<Accessory> list = this.findEntitys(sql.toString(), Accessory.class, new Object[] {});
        return list;
	}
	
	public List<Accessory> selectAccessoryByCode(String resourceCode) {
		StringBuffer sql=new StringBuffer();
    	sql.append(" SELECT *");
    	sql.append(" FROM o2o_guideline");
    	sql.append(" WHERE resource_code=?");
    	 List<Accessory> list = this.findEntitys(sql.toString(), Accessory.class, new Object[] {resourceCode});
         return list;
	}
	
	public boolean saveAccessory(Accessory accessory){
		return this.insert(accessory)>0?true:false;
	}
	
	public boolean updateAccessory(Accessory accessory){
		return this.updateById(accessory)>0?true:false;
	}
	
	public Boolean deleteAccessory(Accessory accessory) {
		return this.deleteByIdWithEntity(accessory)>0?true:false;
	}
}
